// 导入静态路由
import { constantRoutes, asyncRouter } from "@/router";

const state = {
  routes: constantRoutes
};
const mutations = {
  setRoutes(state, newRoles) {
    state.routes = [...constantRoutes, ...newRoles];
  }
};
const actions = {
  getAsyncRoles(context, menus) {
    let routes = asyncRouter.filter(item => menus.includes(item.name));
    routes.push({ path: "*", redirect: "/404", hidden: true });
    context.commit("setRoutes", routes);
    return routes;
  }
};
export default {
  namespaced: true,
  state,
  mutations,
  actions
};
